8934. Marathon 3

 

The race participants were assigned numbers from a to b, and all the information was recorded in the computer, but only in reverse order. Print the athletes’ numbers.

 

Input. Two positive integers a and b (a ≤ b ≤ 1000).

 

Output. Print the athletes’ numbers in decreasing order.

 

Sample input

Sample output

3 7

7 6 5 4 3

 

 

SOLUTION

loop

 

Algorithm analysis

Use a for loop to print the athletes’ numbers. Print the numbers from a to b in decreasing order.

 

Algorithm implementation

Read the input data.

 

scanf("%d %d", &a, &b);

 

Print the athletes’ numbers in decreasing order.

 

for (i = b; i >= a; i--)

  printf("%d ", i);

 

Java implementation

 

import java.util.*;

 

class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int a = con.nextInt();

    int b = con.nextInt();

    for(int i = b; i >= a; i--)

      System.out.print(i + " ");

    con.close();

  }

}

 

Python implementation

Read the input data.

 

a, b = map(int, input().split())

 

Print the athletes’ numbers in decreasing order.

 

for i in range(b, a - 1, -1):

  print(i)